<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增活动')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-huoDong-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">活动名称：</label>
                <div class="col-sm-8">
                    <input name="name" required class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">展示端：</label>
                <div class="col-sm-8">
                    <select name="type" required class="form-control m-b">
                        <option value="">请选择</option>
                        <option value="1">社工端</option>
                        <option value="2">用户端</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片(建议长宽 700*240)：</label>
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input id="file" class="form-control" accept="image/jpg,image/jpeg,image/png" name="file"  type="file">
                        <img style="width: 80px ;height: auto;" src="" id="imgPhoto"  />
                        <input style="display: none"  id="photo" class="form-control" name="photo"   type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">跳转地址：</label>
                <div class="col-sm-8">
                    <input name="url" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否展示：</label>
                <div class="col-sm-8">
                    <select name="isShow" required class="form-control m-b">
                        <option value="">请选择</option>
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "jiajia/huoDong"
        $("#form-huoDong-add").validate({
            focusCleanup: true
        });

        $("#file").bind('change', function () {
            $("#imgPhoto").show();
            $("#imgPhoto").attr("src",URL.createObjectURL($(this)[0].files[0]));
        });

        function uploadFile(idSelector,callback) {
            var formData = new FormData();
            formData.append('file',$(idSelector)[0].files[0]);
            $.modal.loading("图片上传中，请稍后...")
            $.ajax({
                url: "/common/admin/upload/up/single",
                data: formData,
                type: "post",
                dataType: "json",
                processData: false,
                contentType: false,
                success: function(result) {
                    callback(result)
                }
            })
        }

        function submitHandler() {
            if ($.validate.form()) {
                uploadFile("#file",function (res1) {
                    $("#photo").val(res1.url);
                    $.operate.save(prefix + "/add", $('#form-huoDong-add').serialize());
                })
            }
        }
    </script>
</body>
</html>